package com.zrh.jsd.service.studydemo.threadpool;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

public class CompleteFutureRunasyncExceptionTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("mainMethod 执行结束" + mainMethod());
    }

    private static int mainMethod() throws InterruptedException, ExecutionException {
        CompletableFuture<Void> completableFutureOne = CompletableFuture.runAsync(()->{
            try {
                exceptionMethod(true);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        // 提交了一步任务后，主线程可以继续干一些其他的事情
        doSomeThinsElese();
        completableFutureOne.get();
        return 132;
    }

    private static void doSomeThinsElese() throws InterruptedException {
        System.out.println("主线任务开始==doSomeThinsElese===start=");
        TimeUnit.SECONDS.sleep(3);
        System.out.println("主线任务结束==doSomeThinsElese===end=");
    }

    private static int exceptionMethod(boolean bool) throws InterruptedException {
        System.out.println("exceptionMethod===start=");
        TimeUnit.SECONDS.sleep(10);
        if(bool){
            throw new InterruptedException();
        }else{
            return 7;
        }
    }



}
